export class Request {
  static HOST = 'https://apps.zyfuns.com/zyfuns/';
  constructor(url, data) {
    this.url = url;
  }
  request(params, callback) {
    wx.request({
      url: `${Request.HOST}${this.url}`,
      method: 'POST',
      data: params(),
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'cookie': 'PHPSESSID=' + getApp().globalData.phpsessId
      },
      success: (setData) => {
        setData.data.code == -1 || setData.statusCode != 200 ? new error() : new success();

        function success() {
          callback(setData);
        }

        function error() {
          wx.showToast({
            title: '登陆超时',
            icon: 'none',
            duration: 2000,
            mask: true
          })
          setTimeout(function () {
            wx.redirectTo({
              url: '/pages/index/index'
            })
          }, 2000)
        }
      }
    })
  }
}